var RunLayer = cc.Layer.extend({
	arr:null,
	scene:null,
	clock:null,
	ctor:function (parent) {
		this._super();
		this.scene = parent;
		this.scene.addChild(this, 10);
		gg.main = this;
		this.init();
	},
	init:function () {
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callKill = cc.callFunc(function(p){
			var seq = cc.sequence(cc.fadeOut(0.5),cc.callFunc(function(){
				p.removeFromParent(true);	
			}, this));
			p.runAction(seq);
		}, this); 
		
		this.callNext.retain();
		this.callKill.retain();
		//时钟
		this.clock = new Clock(this);
		//水流
		this.water = new Water(this);
		//药品库
		this.lib = new Lib(this);
		
		var shelf=new Shelf(this);
	},
	loadHand:function(pos){
		var hand = new Button(this, 8, TAG_RIGHT, "#hand_right.png", this.callback);
		hand.setPosition(pos);
		var part = new Button(this, 11, TAG_RIGHT_PART, "#hand_right_part.png", this.callback);
		part.setPosition(pos);
	},
	loadBaohe:function(pos){
		this.beaker1 = new Beaker1(this);
		this.addChild(this.beaker1, 20);
		this.loadInLib(this.beaker1, pos, cc.p(640,310));
	},
	loadBeaker:function(pos){
		var action=gg.flow.flow.action;
		if(action==ACTION_DO8){
			this.beaker2 = new Beaker2(this);
			this.addChild(this.beaker2, 20);
			this.loadInLib(this.beaker2, pos, cc.p(163, 144));
		}else if(action==ACTION_DO9){
			this.beaker3 = new Beaker3(this);
			this.addChild(this.beaker3, 20);
			this.loadInLib(this.beaker3, pos, cc.p(163, 144));
		}			
	},
	loadCatheter:function(pos){
		this.catheter = new Catheter(this);
		this.addChild(this.catheter, 20);
		this.loadInLib(this.catheter, pos, cc.p(750, 424),false);
	},
	loadGas:function(pos){
		this.gas = new Gas(this);
		this.addChild(this.gas, 20);
		this.loadInLib(this.gas, pos, cc.p(724, 424),false);
	},
	loadRod:function(pos){
		this.rod = new Rod(this);
		this.addChild(this.rod, 20);
		this.loadInLib(this.rod, pos, cc.p(100, 200));
	},
	loadNacl:function(pos){
		this.nacl = new Nacl(this);
		this.addChild(this.nacl, 20);
		this.loadInLib(this.nacl, pos, cc.p(400, 200));
	},
	loadFilter:function(pos){
		var filter = new Button(this, 10, TAG_PAPER, "#filter_paper1.png", this.callback);
		filter.setScale(1.2);
		filter.setPosition(cc.p(1100, 600));
		var move1=cc.moveTo(1,cc.p(140,350));
		var move2=cc.moveTo(0.6,cc.p(140,289));
		var fad=cc.fadeOut(0);
		var seq=cc.sequence(move1,move2,fad,cc.callFunc(function() {
			var shelf=this.getChildByTag(TAG_SHELF).getChildByTag(TAG_FILTER);
			shelf.setSpriteFrame("ironShelf1.png");
			gg.flow.next();
		}, this));
		filter.runAction(seq);
	},
	loadFlow1:function(){
		var flow=new cc.Sprite("#wpoint.png");
		this.addChild(flow, 5);
		flow.setPosition(cc.p(-46,-47));
		flow.setRotation(-15);
		var move=cc.moveTo(0.6, cc.p(-31,-117));
		var seq=cc.sequence(move,cc.callFunc(function() {
		}, this));
		flow.runAction(seq);
	},
	loadFlow2:function(){
		var flow=new cc.Sprite("#wpoint.png");
		this.addChild(flow, 5);
		flow.setPosition(cc.p(-50,-162));
		flow.setScale(0.8);
		var move=cc.moveTo(0.6, cc.p(-50,-275));
		var seq=cc.sequence(move,cc.callFunc(function() {
			flow.removeFromParent();
		}, this));
		flow.runAction(seq);
	},
	loadInLib:function(obj, pos, tarPos,next,delay){
		obj.setPosition(pos);
		if(next == null){
			next = true;
		}
		if(delay == null){
			delay = 1;
		}		
		var ber = $.bezier(pos, tarPos, delay);
		if(next){
			var seq = cc.sequence(ber, this.callNext);
		}else{
			var seq = cc.sequence(ber);
		}	
		obj.runAction(seq);
	},
	
	kill:function(obj){
		var fade = cc.fadeTo(0.5,0);
		var func = cc.callfunc(function(){
			obj.removeFromParent(true);
		},this);
		var seq = cc.sequence(fade,func);
		obj.runAction(seq)
	},
	flowNext:function(){
		gg.flow.next();
	},
	onExit:function(){
		this._super();
		this.callNext.release();
		this.callKill.release();
	}
});